home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / compute / 1988_02 / wrimage.c < prev    next >
Text File  |  1987-09-22  |  19KB  |  905 lines

  1. /*
  2. WRIMAGE is a word game written by John W. Ratcliff
  3. */
  4.  
  5.  
  6. #define BLACK 0
  7. #define BLUE 1
  8. #define GREEN 2
  9. #define CYAN 3
  10. #define RED 4
  11. #define MAGENTA 5
  12. #define BROWN 6
  13. #define GRAY 7
  14. #define DARK_GRAY 8
  15. #define LIGHT_BLUE 9
  16. #define LIGHT_GREEN 10
  17. #define LIGHT_CYAN 11
  18. #define LIGHT_RED 12
  19. #define LIGHT_MAGENTA 13
  20. #define YELLOW 14
  21. #define WHITE 15
  22.  
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <alloc.h>
  26. #include <string.h>
  27. /*
  28. Protypes here
  29. *
  30. */
  31. extern     char    sec,hsec;
  32. int   keystat();
  33. int   getch(void);
  34. void  sound(int tone,int duration);
  35. void  tprint(
  36.              int x,
  37.              int y,
  38.              int wid,
  39.              int bc,
  40.              int fc,
  41.              char *str
  42.              );
  43. void  flushk(void);
  44. void  setmode(int vidmode);
  45. void  getime(void);
  46. void  getword(void);
  47. void  big_print(char *str);
  48. void  home(int bc,int fc);
  49. int   keystat(void);
  50. void  cursoff(void);
  51. void  plet(void);
  52. void  movlet(void);
  53. void  slide(void);
  54. void  ptime(void);
  55. int   timit(int tn);
  56. int   tinput(char *buf,int x1,int y1,int l,int bc,int fc);
  57. void  discore(void);
  58. int   grand(int rd);
  59. int   getup(void);
  60. void  getlet(void);
  61. void  nexturn(void);
  62. int   poplet(int c);
  63. void  getword(void);
  64. void  dospell(void);
  65. void  clrmid(void);
  66. int   win(void);
  67. int   winner(int wscore);
  68. void  sounder(int tone,int duration);
  69. void  sound2(int tone,int duration);
  70. void  buroing(void);
  71. void  boroing(void);
  72. /* All the variables are global because, as mentioned above, this was my
  73.    first C program and I didn't know better.
  74. */
  75. char blank[2] = {  32, 0 };
  76. char blbd[2]  = { 200, 0 };
  77. char brbd[2]  = { 188, 0 };
  78. char tlbd[2]  = { 201, 0 };
  79. char trbd[2]  = { 187, 0 };
  80. char tbd[2]   = { 205, 0 };
  81. char lbd[2]   = { 186, 0 };
  82. char amount[26] = {
  83.                    1, 3, 3, 2, 1, 4, 2, 4, 1, 6, 5, 1, 3, 1, 1, 3, 6,
  84.                    1, 1, 1, 1, 5, 4, 7, 4, 7
  85.                   };
  86.  
  87. char    *nums[7] = {
  88.                     "1",
  89.                     "2",
  90.                     "3",
  91.                     "4",
  92.                     "5",
  93.                     "6",
  94.                     "7"
  95.                     };
  96. char     *title = { "WRIMAGE" };
  97. int      bc,fc,x,y,i,j,k;
  98. char    **words,*offset;
  99. char    le1,le2,le3,let[3]; /* three letters choosen */
  100. char    names[6][9];
  101. int     scores[6];
  102. char    tstr[2],ibuf[40];
  103. char    vals[10] = { "0123456789" };
  104. int     correct,adscore,length,turn;
  105. int     sound_set;
  106. char    *word;
  107. int     sts,sth;
  108. char    used[15];
  109. int     nn,rd,m,ln,nwords,bas;
  110. int     ts,th,col,t,kk,np,ky,op,echo;
  111. main(argc,argv)
  112. int argc;
  113. char **argv;
  114. {
  115.  
  116. FILE *fph;
  117. int  s,n,a,excon,ns,line,l,err,wtype;
  118.  
  119. if (argc > 2)
  120.    {
  121.     printf("Invalid call to Wrimage\n");
  122.     printf("Usage: WRIMGE <filename>\n");
  123.     printf("Filename is your own text file of words to be used\n");
  124.     printf("Without a filename passed the default word list is used\n");
  125.     exit(1);
  126.    }
  127.  
  128. if (argc == 2)
  129.     wtype = 0;
  130.    else
  131.     wtype=1;
  132.  
  133. tstr[1]=0;
  134. setmode(3);  /* Get in 80x25 color graphics mode */
  135. words=malloc(4500*2);
  136. if (words == NULL)
  137.  {
  138.   printf("Couldn't allocate local memory for word list\n");
  139.   exit(1);
  140.  }
  141. word=malloc(32500);
  142. if (word == NULL)
  143.  {
  144.   printf("Couldn't allocate local memory for word list\n");
  145.   exit(1);
  146.  }
  147.  
  148. getime();
  149. i=hsec*256+sec;
  150. srand(i);
  151. if (wtype)
  152.    fph=fopen("wrimage.lst", "rb");
  153.   else
  154.    fph=fopen(argv[1], "rb");
  155.  
  156. if (fph == NULL)
  157.    {
  158.     if (wtype)
  159.        printf("Couldn't find standard word list file WRIMAGE.LST\n");
  160.       else
  161.        printf("Couldn't find user word list '%s'\n",argv[1]);
  162.     exit(1);
  163.    }
  164. s=1;
  165. n=32500;
  166. home(BLACK,LIGHT_GREEN);
  167. printf("Reading in word list file\n");
  168. i=fread(word, s, n, fph);
  169. fclose(fph);
  170. printf("Setting up word list\n\n");
  171. /* This routine translates the word list read in from dis */
  172. /* j is the current character in the word list being examined */
  173. /* i is the number of characters in the word list read in */
  174. /* nwords is the number of words compiled by this routine */
  175. /* n is the current character in the new list being created */
  176. /* words is the pointer array pointing to words entered into the list */
  177. err=0;
  178. if (i>0) i--;
  179. j      = 0;
  180. nwords = 0;
  181. line   = 0;
  182. n      = 0;
  183.  
  184. do
  185.    {
  186.     words[nwords] = &word[n];
  187.     excon = 0;
  188.     ns = n;
  189.     do {
  190.         a=word[j];
  191.         if (a >= 'a' && a <= 'z') a-=32;
  192.         if ( (a < 'A' || a > 'Z') && a != 13)
  193.             excon=1;
  194.            else
  195.            {
  196.             word[n]=a;
  197.             n++;
  198.            }
  199.         j++;
  200.        } while (a !=13 && j<i);
  201.     if (excon)
  202.       word[n]=0;
  203.        else
  204.       word[n-1]=0;
  205.     if (a == 13)
  206.        {
  207.         if (word[j] == 10) j++;
  208.         line++;
  209.        }
  210.     if (excon)
  211.        {
  212.         printf("LINE->%4D: Word at line %d contains invalid characters.\n",line,line);
  213.        }
  214.     else
  215.     {
  216.      l=n-ns-1;
  217.      if (l < 4)
  218.        {
  219.         printf("LINE->%4D: Word '%s' at line %d is too short.\n",line,words[nwords],line);
  220.         excon=1;
  221.        }
  222.       if (l > 15)
  223.        {
  224.         printf("LINE->%4D: Word '%s' at line %d is too long.\n",line,words[nwords],line);
  225.         excon=1;
  226.         }
  227.     }
  228.     if (excon) { n=ns; err++; }
  229.      else
  230.        nwords++;
  231.   } while (j < i && nwords < 4500);
  232. if (nwords == 4500)
  233.    {
  234.     printf("You had more thant 4500 words in your word list\n");
  235.     printf("the extra ones will be ignored\n");
  236.    }
  237. if (nwords < 20)
  238.    {
  239.     printf("Sorry but you must have at least 20 words in your word list to play\n");
  240.     exit(1);
  241.    }
  242. if (err)
  243.    {
  244.     printf("\n%d errors were encountered reading in the word list.\n",err);
  245.     printf("Do you wish to continue (y/n)?");
  246.     do
  247.      {
  248.       a=getup();
  249.      } while (a != 'Y' && a != 'N');
  250.     if (a == 'N')
  251.        {
  252.         goto leave;
  253.        }
  254.     }
  255.  
  256. home(BLACK,BLACK);
  257. cursoff();
  258.  
  259.  tprint(5,1,0,BLACK,LIGHT_CYAN,"    Copyright 1987, COMPUTE! Publications, Inc.");
  260.  tprint(5,0,0,BLACK,LIGHT_CYAN,"Welcome to Wrimage: A word game written by John W. Ratcliff.");
  261.  y=5;
  262.  bc=BLUE;
  263.  fc=GRAY;
  264.  big_print(title);
  265.  y=7;
  266.  bc=MAGENTA;
  267.  for (x=4,i=0; i<7; i++,x=x+5)
  268.   {
  269.    tstr[0]=title[i];
  270.    plet();
  271.   }
  272.   tprint(18,23,0,BLACK,YELLOW,"Press a key to begin");
  273.  getch();
  274. newgame:
  275. /* Ask for sound in this do loop */
  276.  home(BLACK,BLACK);
  277.  for (i=0; i<6; i++) scores[i]=0;
  278.  turn=0;
  279.  tprint(10,8,0,BLACK,LIGHT_CYAN,"Do you want sound in your game? (y/n)");
  280. do {
  281.     x=getup();
  282.     switch (x)
  283.      {
  284.       case 'Y': sound_set = 1;
  285.                 sound(1000,2);
  286.                 break;
  287.       case 'N': sound_set = 0;
  288.                 break;
  289.      }
  290.     }
  291.     while (x != 'Y' && x != 'N' && x != 27);
  292. if (x == 27) goto leave;
  293.  
  294. moder:
  295. if (wtype)
  296.  {
  297. do {
  298.   home(BLACK,BLACK);
  299.   tprint(10,8,0,BLACK,LIGHT_CYAN,"Play at what level?");
  300.   tprint(10,10,0,BLACK,LIGHT_CYAN,"  1.  Easy words.");
  301.   tprint(10,11,0,BLACK,LIGHT_CYAN,"  2.  Medium words.");
  302.   tprint(10,12,0,BLACK,LIGHT_CYAN,"  3.  Hard words.");
  303.   tprint(10,13,0,BLACK,LIGHT_CYAN,"  4.  Mixed levels.");
  304.   x=getch();
  305.   switch(x)
  306.      {
  307.       case '1':  bas    = 1501;
  308.                  nwords = 2000;
  309.                  break;
  310.       case '2':  bas    = 2000;
  311.                  break;
  312.       case '3':  bas    = 0;
  313.                  nwords = 1500;
  314.                  break;
  315.       case '4':  bas    = 0;
  316.                  break;
  317.      }
  318.   } while ( (x < '1' || x > '4') && x !=27);
  319. if (x == 27) goto newgame;
  320.  } else
  321.   bas=0;
  322.  
  323. backup:
  324.   home(BLACK,BLACK);
  325.   tprint(2,23,0,BLACK,LIGHT_MAGENTA,"    Copyright 1987, COMPUTE! Publications, Inc.");
  326.   tprint(5,0,0,BLACK,LIGHT_CYAN,"Welcome to Wrimage: A word game written by John W. Ratcliff.");
  327.   tprint(0,2,0,BLACK,CYAN,"Make entry then press ENTER.  Press ESC to back-up an entry.");
  328.   tprint(0,3,0,BLACK,CYAN,"Enter information below:");
  329.   tprint(25,3,0,BLACK,RED,"You may press Control-C to break out of this program.");
  330.   tprint(0,5,0,BLACK,CYAN,"How many players? (1-6):");
  331.   do
  332.     {
  333.      j=tinput(ibuf,24,5,1,GRAY,BLACK);
  334.     } while ( (ibuf[0]<'1' || ibuf[0]>'6') && j != 27 );
  335.   if (j == 27 && wtype) goto moder;
  336.   if (j == 27 && !wtype) goto newgame;
  337.  
  338.   np=ibuf[0]-'0';
  339.  
  340. reent:
  341.  j=0;
  342.  kk=0;
  343.  do
  344.    {
  345.     tprint(0,7+kk*2,0,BLACK,CYAN,"What is your name player #");
  346.     tprint(26,7+kk*2,0,BLACK,CYAN,nums[kk]);
  347.     tprint(27,7+kk*2,0,BLACK,CYAN,"?");
  348.     do {
  349.         j=tinput(&names[kk][0],28,7+kk*2,9,GRAY,BLACK);
  350.        } while (strlen(names[kk]) == 0 && j != 27);
  351.     if (j != 27) kk++;
  352.     if (j == 27 && kk > 0)
  353.      {
  354.       tprint(0,7+kk*2,80,BLACK,BLACK,blank);
  355.       kk--;
  356.       j=0;
  357.      }
  358.     } while ( kk < np && j !=27);
  359. if (kk == 0) goto backup;
  360. tprint(0,20,80,BLACK,BLACK," ");
  361. tprint(0,21,80,BLACK,BLACK," ");
  362. tprint(10,22,0,BLACK,LIGHT_CYAN,"Is this correct? (Y/N)");
  363. do
  364.  {
  365.   j=getup();
  366.  } while ( j != 'Y' && j != 'N' && j != 27);
  367.  if (j == 27)
  368.    {
  369.     tprint(0,22,80,BLACK,BLACK,blank);
  370.     j=np-1; goto reent;
  371.    }
  372.  if (j == 'N')
  373.    {
  374.     goto backup;
  375.    }
  376.  
  377. home(BLACK,BLACK);
  378. tprint(0,23,0,BLACK,WHITE,"Letter scoring values:");
  379. for (x=23,j=0; j<7; j++,x=x+j+4)
  380.     {
  381.       tprint(x,23,0,BLACK,WHITE,nums[j]);
  382.       tprint(x+1,23,0,BLACK,WHITE,".");
  383.       tprint(x+2,23,j+1,j+1,j+1,blank);
  384.     }
  385.  
  386. neword:
  387.   discore();
  388.   x=5;
  389.   y=1;
  390.   bc=BLUE;
  391.   fc=GRAY;
  392.   getword();
  393.   big_print(offset);
  394. agn:
  395.   clrmid();
  396.   discore();
  397.   tprint(5,10,0,BLACK,CYAN,"C)hoose letters or S)pell the word?");
  398.   op=0;
  399.   j=timit(0);
  400.   tprint(0,10,80,BLACK,BLACK,blank);
  401.   if (j == 0)  { nexturn(); goto agn; }
  402.   if (j == 'S')
  403.      {
  404.       dospell();
  405.       if (correct)
  406.          { 
  407.           scores[turn]=scores[turn]+adscore;
  408.           discore();
  409.           clrmid();
  410.           buroing();
  411.           tprint(10,10,0,BLACK,LIGHT_CYAN,"You spelled the word correctly");
  412.           tprint(42,10,0,BLACK,LIGHT_CYAN,&names[turn][0]);
  413.           wtr:
  414.           for (k=0; k<4; k++)
  415.            {
  416.             getime();
  417.             i=sec;
  418.             do { getime(); } while(i == sec);
  419.             }
  420.           nexturn();
  421.           i=winner(69);
  422.           if (i>=0)
  423.             {
  424.              clrmid();
  425.              boroing();
  426.              tprint(10,10,0,BLACK,LIGHT_CYAN,"Congratulations, the winner is...");
  427.              tprint(15,11,0,BLACK,GREEN,&names[i][0]);
  428.              for (k=0; k<5; k++)
  429.                {
  430.                 getime();
  431.                 i=sec;
  432.                 do { getime(); } while(i == sec);
  433.                }
  434.              clrmid();
  435.              tprint(10,10,0,BLACK,LIGHT_CYAN,"Play another game? (Y/N)");
  436.              do {
  437.                  j=getup();
  438.                 } while( (j != 'Y') && (j != 'N'));
  439.              if (j == 'N')  { goto leave; }
  440.              goto newgame;
  441.            }
  442.           goto neword;
  443.         }
  444.      else scores[turn]=scores[turn]-5;
  445.    nexturn();
  446.    goto agn;
  447.  }
  448.   getlet();
  449.   fc=GRAY;
  450.   movlet();
  451.   tprint(14,14,0,BLACK,CYAN,"Press SPACE to pass");
  452.  
  453.   op=1;
  454.   j=timit(0);
  455.   if (j == 0)  { nexturn(); goto agn; }
  456.   kk=poplet(j);
  457.   scores[turn]+=kk;
  458.   discore();
  459.   i=win();
  460.   if (i)
  461.     {
  462.      clrmid();
  463.      buroing();
  464.      tprint(5,7,0,BLACK,LIGHT_CYAN,".........is the word.");
  465.      goto wtr;
  466.     }
  467.   if (kk <= 0)  nexturn();
  468. goto agn;
  469.  
  470. leave: home(BLACK,YELLOW);
  471. leave2: printf("Thankyou for playing Wrimage."); exit(0);
  472.  
  473. }
  474.  
  475. void big_print(str)
  476. char *str;
  477.  {
  478.   i=-1;
  479.   for (x=0,i++;str[i]>0; i++,x=x+5)
  480.    {
  481.     used[i]=0;
  482.     tstr[0]=32;
  483.     slide();
  484.   }
  485.    tprint(x,y,80-x,BLACK,fc,blank);
  486.    tprint(x,y+1,80-x,BLACK,fc,blank);
  487.    tprint(x,y+2,80-x,BLACK,fc,blank);
  488.    length=i;
  489.  }
  490.  
  491. void plet(void)
  492.  {
  493.    tprint(x,y,0,bc,fc,tlbd);
  494.    tprint(x+1,y,0,bc,fc,tbd);
  495.    tprint(x+2,y,0,bc,fc,tbd);
  496.    tprint(x+3,y,0,bc,fc,tbd);
  497.    tprint(x+4,y,0,bc,fc,trbd);
  498.    tprint(x,y+1,0,bc,fc,lbd);
  499.    tprint(x+1,y+1,0,bc,fc,blank);
  500.    if (bc > 1 )
  501.       tprint(x+2,y+1,1,bc,BLACK,tstr);
  502.    else
  503.       tprint(x+2,y+1,1,bc,LIGHT_CYAN,tstr);
  504.    tprint(x+3,y+1,0,bc,fc,blank);
  505.    tprint(x+4,y+1,0,bc,fc,lbd);
  506.    tprint(x,y+2,0,bc,fc,blbd);
  507.    tprint(x+1,y+2,0,bc,fc,tbd);
  508.    tprint(x+2,y+2,0,bc,fc,tbd);
  509.    tprint(x+3,y+2,0,bc,fc,tbd);
  510.    tprint(x+4,y+2,0,bc,fc,brbd);
  511.  }
  512.  
  513. void movlet(void)
  514. {
  515.  y=9;
  516.  for (x=13,i=0; i<3; i++,x=x+6)
  517.   {
  518.    tstr[0]=let[i];
  519.    bc=amount[(let[i]-65)];
  520.    slide();
  521.   }
  522. }
  523.  
  524.  
  525. void slide(void)
  526. {
  527. int tx,ty;
  528. tx=x;
  529. ty=y;
  530. x=75;
  531. for (y=0; y<=ty; y++)
  532.   {
  533.    if (y>0) tprint(x,y-1,5,BLACK,BLACK,blank);
  534.    plet();
  535.   }
  536. tprint(x,y-1,5,BLACK,BLACK,blank);
  537. for (x=74; x>=tx; x--)
  538.   {
  539.    tprint(x+5,y,0,BLACK,BLACK,blank);
  540.    tprint(x+5,y+1,0,BLACK,BLACK,blank);
  541.    tprint(x+5,y+2,0,BLACK,BLACK,blank);
  542.    plet();
  543.    }
  544.  x=tx; y=ty;
  545.  sounder(1000,1);
  546.  }
  547.  
  548. void home(bc,fc)
  549. int bc,fc;
  550.  {
  551. for (i=0; i<26; i++)
  552.  tprint(0,i,80,bc,fc," ");
  553.  }
  554.  
  555. void ptime(void)
  556.  {
  557.   rd++;
  558.   sprintf(vals,"%d",ts);
  559.   ln=strlen(vals);
  560.   if (ln == 2)
  561.      tprint(18,7,0,BLACK,col,vals);
  562.      else { tprint(18,7,0,BLACK,BLACK,blank);
  563.                 tprint(19,7,0,BLACK,col,vals);
  564.           }
  565.   tprint(20,7,0,BLACK,col,":");
  566.   sprintf(vals,"%d",th);
  567.   i=strlen(vals);
  568.   if (i>0)
  569.       tprint(21,7,2,BLACK,DARK_GRAY,vals);
  570.  }
  571.  
  572. int timit(tn)
  573. int     tn;
  574. {
  575.   tprint(17,6,0,BLACK,GRAY,tlbd);
  576.   tprint(23,6,0,BLACK,GRAY,trbd);
  577.   tprint(17,8,0,BLACK,GRAY,blbd);
  578.   tprint(23,8,0,BLACK,GRAY,brbd);
  579.   tprint(17,7,0,BLACK,GRAY,lbd);
  580.   tprint(23,7,0,BLACK,GRAY,lbd);
  581.   for (i=18; i<23; i++)
  582.    {
  583.     tprint(i,6,0,BLACK,GRAY,tbd);
  584.     tprint(i,8,0,BLACK,GRAY,tbd);
  585.    }
  586.  
  587.   flushk();
  588.   col=CYAN;
  589. if (tn == 0)
  590.  {
  591.   getime();
  592.   sts=sec;
  593.   sth=hsec;
  594.   ts=30;
  595.   th=0;
  596.  }
  597. do
  598.  {
  599.   if (ts<6)  col=RED;
  600.   ptime();
  601.   getime();
  602.   ts=sec;
  603.   th=hsec;
  604.   if (ts >= sts)  ts=29-(ts-sts);
  605.    else ts=29-((60-sts)+ts);
  606.    if (th >= sth)  th=99-(th-sth);
  607.     else th=99-((100-sth)+th);
  608.   i=keystat();
  609.   if (i != 0 )
  610.     {
  611.      i=getup();
  612.      if ( (i < 'A' || i > 'Z') && i!=32) i=0;
  613.       if ((i == 32) && (op == 1))  i=1;
  614.         else
  615.       {
  616.         if ((op == 0) && ( i != 'C' ) && ( i != 'S' ))  i=0;
  617.         if ((op == 1) && (i != let[0]) && (i != let[1]) && (i != let[2]))  i=0;
  618.       }
  619.     }
  620.  }  while ( ( ts >=0 ) && ( i == 0 ) );
  621.    if (i == 1)  i=0;
  622.    ky=i;
  623.    if (ts == 0 )  { th=0; ptime(); }
  624.   srand(rd);
  625.   return(ky);
  626. }
  627.  
  628.  
  629.  
  630. int tinput(buf,x1,y1,l1,bc1,fc1)
  631. char buf[];
  632. int x1,y1,l1,bc1,fc1;
  633. {
  634. buf[0]=0;
  635.  
  636. j=0;
  637. t=0;
  638. while ( j != 27 && j != 13 )
  639.  {
  640.   tprint(x1,y1,l1,bc1,fc1,buf);
  641.   j=getch();
  642.   if ( !j )
  643.     {
  644.      j=getch();
  645.      if (j==75) j=8;
  646.       else j=0;
  647.     }
  648.  
  649.   if ( ((j>32 && j<127) || (j==32 && t>0)) && t<l1)
  650.    {
  651.     buf[t]=j;
  652.     t=t+1;
  653.     buf[t]=0;
  654.    }
  655.  
  656.   if (j==8 && t>0)
  657.    {
  658.     t=t-1;
  659.     buf[t]=0;
  660.    } else if ( (l1 == 1) && (t == 1) )  t=0;
  661.  
  662.  }
  663. return(j);
  664. }
  665.  
  666. void discore(void)
  667. {
  668. /* this routine will display the players names and scores */
  669. int sc;
  670. for (j=0; j<np; j++)
  671. {
  672.   sc=scores[j];
  673.   if (sc<-70)  sc=-70;
  674.   if (sc>70)  sc=70;
  675.   if (sc<0)  i=-sc; else i=sc;
  676.  
  677.   if (j == turn)  tprint(0,16+j,15,GREEN,BLACK,&names[j][0]);
  678.  
  679.     else tprint(0,16+j,15,BLACK,GREEN,&names[j][0]);
  680.  
  681.  if (sc>0)  tprint(10,16+j,sc,BLUE,BLUE,blank);
  682.  if (sc<0)  tprint(10,16+j,-sc,RED,RED,blank);
  683.  
  684.   if (i<70)  for (; i<70; i++) tprint(i+10,16+j,0,BLACK,GRAY,tbd);
  685. }
  686. }
  687.  
  688. int grand(rd)
  689. int rd;
  690. {
  691. /* this routine will generate a random number between 0 and the int requested */
  692.  return(rand()%rd);
  693. }
  694.  
  695. int getup()
  696. {
  697.  
  698.  j=getch();
  699.   if (j>='a' && j<='z')  j=j-32;
  700.  return(j);
  701.  }
  702.  
  703. void getlet(void)
  704. {
  705.  
  706.  j=grand(length);
  707.  le1=offset[j];
  708. do
  709.  {
  710.  j=grand(26)+65;
  711.  } while ( j    == le1 );
  712.  le2=j;
  713.  do
  714.   {
  715.   j=grand(26)+65;
  716.   } while ( (j == le1) || (j == le2) );
  717.   le3=j;
  718.  
  719.  j=grand(3);
  720.  let[j]=le1;
  721.  if (j == 0 )  { let[1]=le2; let[2]=le3; }
  722.  if (j == 1 )  { let[0]=le2; let[2]=le3; }
  723.  if (j == 2 )  { let[0]=le2; let[1]=le3; }
  724.  if (let[1] == 'U')  { let[1]=let[0]; let[0]='U'; }
  725.  
  726.  }
  727.  
  728. void nexturn(void)
  729. {
  730.  turn++;
  731.   if (turn == np)  turn=0;
  732.   discore();
  733. }
  734.  
  735. int poplet(c)
  736. int c;
  737. {
  738.  
  739.  y=10;
  740.  for (x=13,i=0; i<3; i++,x=x+6)
  741.   {
  742.    tstr[0]=let[i];
  743.    fc=GRAY;
  744.    bc=amount[(let[i]-65)];
  745.    if (let[i] != c)  { bc=BLACK; fc=BLACK; tstr[0]=32; }
  746.    plet();
  747.   }
  748.  
  749. tprint(0,14,80,BLACK,BLACK,blank);
  750.  
  751.  i=0;
  752.  for (j=0; j<length; j++)
  753.   {
  754.    if ( (offset[j] == c) && ! used[j] )
  755.          {
  756.               clrmid();
  757.               y=2; x=5*j;  fc=GRAY;
  758.               tstr[0]=c;
  759.               bc=GREEN;
  760.               sounder(900,2);
  761.               plet();
  762.               getime();
  763.               k=sec;
  764.               do { getime(); } while(k == sec);
  765.               bc=MAGENTA;
  766.               plet();
  767.               used[j]=1;
  768.               i+=amount[c-65];
  769.              }
  770.    }
  771. getime();
  772. j=sec;
  773. do { getime(); } while (j == sec);
  774.   if (i == 0)
  775.    {
  776.     sounder(8000,2);
  777.     i-=amount[c-65];
  778.     getime();
  779.     j=sec;
  780.     do { getime(); } while (j == sec);
  781.    }
  782.  return(i);
  783.  }
  784.  
  785. void getword(void)
  786. {
  787. int b;
  788. i=grand(nwords-bas)+bas;
  789. b=i;
  790. for (;words[i] == NULL;)
  791.  {
  792.    i++;
  793.    if (i == nwords) i=bas;
  794.    if (i == b)
  795.       {
  796.        home(BLACK,YELLOW);
  797.        printf("You have used up all of the words available\n");
  798.        boroing();
  799.        i=winner(-1000);
  800.        printf("Congratulations, the winner is...%s\n",names[i]);
  801.        exit(1);
  802.       }
  803.  }
  804.  offset=words[i];
  805.  words[i]=NULL;
  806. }
  807.  
  808.  
  809. void dospell(void)
  810. {
  811. int jk,tn;
  812. tn=0;
  813. adscore=0;
  814. tprint(5,10,0,BLACK,CYAN,"Type the MISSING letters in the word.");
  815. correct=1;
  816. for (jk=0; jk<length && correct; jk++)
  817.  {
  818.     for (; used[jk] && jk<length; jk++);
  819.     if (jk < length)
  820.     {
  821.       op=2;
  822.       i=timit(tn);
  823.       if (tn == 0)  tn=1;
  824.       if (i == offset[jk])
  825.               {
  826.                 sounder(1200,1);
  827.                 y=2; x=5*jk; bc=RED; fc=GRAY;
  828.                 tstr[0]=i; plet();
  829.                 used[jk]=1;
  830.                 adscore=adscore+amount[i-65]+4;
  831.               }
  832.                else
  833.                {
  834.                sounder(8000,2);
  835.                y=2; x=5*jk; bc=GREEN; fc=GRAY;
  836.                tstr[0]=i; plet();
  837.                getime();
  838.                i=sec;
  839.                do { getime(); } while (i == sec);
  840.                getime();
  841.                i=sec;
  842.                do { getime(); } while (i == sec);
  843.                bc=BLUE;
  844.                tstr[0]=32; plet();
  845.                correct=0;
  846.                }
  847.     }
  848.    }
  849. }
  850.  
  851. void clrmid(void)
  852.  {
  853.   for (m=5; m<15; m++) tprint(0,m,80,BLACK,BLACK,blank);
  854.  }
  855.  
  856. int win()
  857. {
  858.  i=1;
  859.  for (j=0; j<length; j++)
  860.     {
  861.       if (! used[j])  i=0;
  862.     }
  863. return(i);
  864. }
  865.  
  866. int winner(j)
  867. int j;
  868. {
  869.  i=-1;
  870.  for (k=0; k<np; k++)
  871.   {
  872.    if (scores[k]>j)  
  873.      {
  874.       i=k;
  875.       j=scores[k];
  876.      }
  877.    }
  878.   return(i);
  879.  }
  880.  
  881. void sounder(tone,duration)
  882. int     tone,duration;
  883. {
  884. if (sound_set == 1)  sound(tone,duration);
  885. }
  886.  
  887. void buroing(void)
  888. {
  889. int tone;
  890. if (sound_set == 1)
  891.    {
  892.     for (tone=1000; tone < 10000; tone=tone+50) sound2(tone,500);
  893.    }
  894. }
  895.  
  896. void boroing(void)
  897. {
  898. int tone;
  899. if (sound_set == 1)
  900.    {
  901.     for (tone=1000; tone < 10000; tone=tone+50) sound2(tone,3000);
  902.    }
  903. }
  904.  
  905.